package com.codered;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;

public class NoteActivity extends Activity {

	/**
	 * Variables
	 */
	
	// Constants
	private static String TAG = "NoteActivity";
	public static boolean DEBUG = true;
	
	
	protected String filename;
	protected String contents;

	
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notes);
        
        String[] filelist = fileList();
        if (DEBUG) Log.i(TAG, "Filename: " + Arrays.toString(filelist));
    }
    
    @Override
    public void onPause() {
    	EditText filenameField = (EditText)findViewById(R.id.filename_field);
    	EditText filecontentField = (EditText)findViewById(R.id.filecontent_field);
    	filename = filenameField.getText().toString();
    	contents = filecontentField.getText().toString();
    	saveAsFile();
    	super.onPause();
    }
    
    
	
    
    
    
    
    
    
    protected void saveAsFile() {
    	try {
    		FileOutputStream fos = openFileOutput(this.filename, NoteActivity.MODE_PRIVATE);
    		fos.write(this.contents.getBytes());
    		fos.close();
    	} catch (FileNotFoundException e) {
    	} catch (IOException e) {
    	}
    }
	
}
